﻿@page "/sso/client"
@inherits AdminCompontentBase

<PageTitle>
    @T("Client")
</PageTitle>

<DefaultCard>
    <AutoHeight>
        <HeaderContent>
            <div class="d-flex mb-6">
                <SSearch @bind-Value="_clientPaginationDto.Search" OnEnter="SearchKeyHandler" />
                <MSpacer />
                <SButton Small OnClick="_addClientDialog.Show" BorderRadiusClass="rounded-lg">
                    <SIcon Size=18 IsDefaultToolTip="false">@IconConstants.Add</SIcon>
                    <span class="ml-2 btn">@T("Add")</span>
                </SButton>
            </div>           
        </HeaderContent>
        <AutoHeightContent>
            <SDataTable
                Height="@("calc(100vh - 288px)")"
                Headers="@_headers" 
                Items="_paginationDto.Items" 
                TItem="ClientDto"
                ItemsPerPage="_clientPaginationDto.PageSize">

                <HeaderColContent Context="header">
                    <span>@header.Text</span>
                </HeaderColContent>
                <ItemColContent>
                    @switch (context.Header.Value)
                    {
                        case nameof(ClientDto.LogoUri):
                            <div class="hover-pointer d-flex">
                                <MAvatar Size=48>
                                    <img src="@context.Item.LogoUri" />
                                </MAvatar>
                                <div class="ml-4 block-center">
                                    <div>@context.Item.ClientName</div>
                                </div>
                            </div>
                            break;
                        case nameof(ClientDto.Description):
                            <span class="description">@context.Item.Description</span>
                            break;
                        case nameof(ClientDto.Enabled):
                            <EnableChip Value=context.Item.Enabled />
                            break;
                        case "Action":
                            <div class="d-flex">
                                <MButton Class="mr-4" Icon OnClick="()=>OpenUpdateDialog(context.Item.Id)">
                                    <SIcon Tooltip="@T("Edit")" Size="20" Color="regular">@IconConstants.Update</SIcon>
                                </MButton>
                                <MButton Class="mr-4" Icon OnClick="()=> OpenRemoveDialog(context.Item)">
                                    <SIcon Tooltip="@T("Delete")">@IconConstants.Remove</SIcon>
                                </MButton>
                            </div>
                            break;
                        default:
                            <span>@context.Value</span>
                            break;
                    }
                </ItemColContent>
            </SDataTable>
        </AutoHeightContent>
        <FooterContent>
            <SPagination Class="mt-4" Page="_clientPaginationDto.Page" PageSize=_clientPaginationDto.PageSize 
                        Total=_paginationDto.Total PageChanged="PageChangedHandler" PageSizeChanged="PageSizeChangedHandler"/>
        </FooterContent>
    </AutoHeight>
</DefaultCard>

<AddClientDialog @ref="_addClientDialog" OnSuccessed="LoadData" />
<UpdateClientDialog @ref="_updateClientDialog" OnSuccessed="LoadData"/>